package com.campus.service.impl;

import com.campus.dao.TeacherDao;
import com.campus.dto.TeacherDto;
import com.campus.model.Teacher;
import com.campus.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc: 教师服务实现类
 * @author: hjm
 * @date: 2024/11/17
 */
@Service
public class TeacherServiceImpl implements TeacherService {

    private final TeacherDao teacherDao;

    public TeacherServiceImpl(TeacherDao teacherDao) {
        this.teacherDao = teacherDao;
    }

    /**
     * 创建教师
     *
     * @param teacherDto 教师DTO对象
     * @return 受影响的行数
     */
    @Override
    public int createTeacher(TeacherDto teacherDto) {
        Teacher teacher = new Teacher();
        teacher.setTeacherName(teacherDto.getTeacherName());
        teacher.setSubject(teacherDto.getSubject());
        teacher.setProfession(teacherDto.getProfession());
        teacher.setSchool(teacherDto.getSchool());
        teacher.setIntroduce(teacherDto.getIntroduce());
        teacher.setLoginId((long) teacherDto.getLoginId());
        return teacherDao.createTeacher(teacher);
    }

    /**
     * 根据ID获取教师信息
     *
     * @param id 教师ID
     * @return 教师对象
     */
    @Override
    public Teacher getTeacherById(int id) {
        return teacherDao.getTeacherById(id);
    }

    /**
     * 根据筛选条件获取教师列表
     *
     * @param subject 科目
     * @param school  学校
     * @return 教师列表
     */
    @Override
    public List<Teacher> getTeachersByFilter(String subject, String school) {
        return teacherDao.getTeachersByFilter(subject, school);
    }
}